Repository navigation
Conversation
There was a problem hiding this comment.
🤖 AI code review
This PR extends the symlink-escape validation from #6545 to the remaining local packaging/upload paths: a new _validate_file_symlink_within_parent helper plus an allowed_roots option and _huggingface_cache_blobs_dirs in common_utils.py, the non-repack tar_and_upload_dir path, and the sagemaker-serve Uploader plus the DJL/TGI/TEI/MMS direct code-dir uploads. The logic is consistent with the retrieved precedent (reuse of _validate_symlinks_within_root, HF cache blobs/ allowance, os.path.commonpath-based containment), imports/helpers all exist at base, and there is good unit-test coverage. My only substantive note is uneven test coverage across the four serve servers; the core logic looks correct.
Reviewed commit 06d07b8. Automated review; verify before acting.
| ) | ||
|
|
||
| code_dir = Path(model_path).joinpath("code") | ||
| _validate_model_dir_symlinks(str(code_dir)) |
There was a problem hiding this comment.
🟡 Low: The identical _validate_model_dir_symlinks(str(code_dir)) guard was added to four servers (DJL, MMS, TEI, TGI), but only TGI has a new unit test (TestSageMakerTgiServingSymlinks). Since these are independent call sites rather than a shared helper call, a regression in any of DJL/TEI/MMS (e.g. a dropped import or a changed code_dir computation) would go uncaught. Consider adding an equivalent symlink-rejection test for the other three servers, or parametrizing a single test across them.
Summary
Extends the packaging symlink checks from PR 6545 to the remaining local packaging and upload paths, so
ModelBuilderbehaves the same whichever path it takes.Changes
sagemaker-core/src/sagemaker/core/common_utils.py_validate_file_symlink_within_parent(): a file input that is a symlink must resolve inside the directory that contains it (for exampleinference.py -> src/inference.py)._validate_symlinks_within_root()accepts an optionalallowed_rootslist._huggingface_cache_blobs_dirs(), which returns the cache'sblobs/directory for paths inside a Hugging Face cache snapshot.inference_scriptand file dependencies.sagemaker-core/src/sagemaker/core/fw_utils.pytar_and_upload_dirapplies the same restricted-path validation as the repack path tosource_dir, the entry point, and dependencies, and applies the file-symlink check to file inputs.sagemaker-serveutils/uploader.py:Uploader.uploadandupload_uncompressedcheckmodel_pathfor symlinks that resolve outside it before uploading. Hugging Face cache snapshots, whose files link into the cache'sblobs/directory, are allowed.Behavior change
ValueError. Pass the target path directly, or copy it into the directory.source_dir, the entry point, and dependencies under restricted locations now raiseValueError, matching the repack path.model_paththat contains symlinks resolving outside it now raisesValueError, except for links into a Hugging Face cacheblobs/directory.Testing
sagemaker-core/tests/unit/test_common_utils.py,sagemaker-core/tests/unit/test_fw_utils.py,sagemaker-serve/tests/unit/utils/test_uploader.py, andsagemaker-serve/tests/unit/model_server/test_tgi_server.py.sagemaker-coreandsagemaker-serveunit suites pass (pre-existing local-mode and optional-dependency failures aside), as do thesagemaker-mlopsworkflow tests.black,flake8,pydocstyle, andpylintpass for both submodules.